import React from 'react';
import {createBrowserRouter} from 'react-router-dom'

import MainLayout from "../layout/MainLayout";
import ManageLayout from "../layout/ManageLayout";
import QuestionLayout from "../layout/QuestionLayout";
import Home from "../pages/Home";
import Login from "../pages/Login";
import Register from "../pages/Register";
import NotFound from "../pages/NotFound";
import List from "../pages/manage/List";
import Trash from "../pages/manage/Trash";
import Star from "../pages/manage/Star";
import Stat from "../pages/question/Stat";
import Edit from "../pages/question/Edit";

const routerConfig = createBrowserRouter([
    {
        path: '/',
        element: <MainLayout/>,
        children: [
            {
                index: true,
                element: <Home/>
            },
            {
                path: '/login',
                element: <Login/>
            },
            {
                path: '/register',
                element: <Register/>
            },
            {
                path: '/manage',
                element: <ManageLayout/>,
                children: [
                    {
                        path: 'list',
                        element: <List/>
                    },
                    {
                        path: 'star',
                        element: <Star/>
                    },
                    {
                        path: 'trash',
                        element: <Trash/>
                    }
                ]
            },
            {
                path: 'question',
                element: <QuestionLayout/>,
                children: [
                    {
                        path: 'edit/:id',
                        element: <Edit/>
                    },
                    {
                        path: 'stat/:id',
                        element: <Stat/>
                    }
                ]
            },

            {
                path: '*',
                element: <NotFound/>
            }

        ]
    }
])
export const LOGIN_PATH = '/login';
export const REGISTER_PATH = '/register';
export const MANAGE_INDEX_PATH = '/manage/list';

export const HOME_PATH = '/';

export function isLoginOrRegisterPath(path: string) {
    if ([LOGIN_PATH, REGISTER_PATH].includes(path)) {
        return true
    } else {
        return false
    }
}

export function isNoNeedUserInfoPath(path: string) {
    if ([HOME_PATH, LOGIN_PATH, REGISTER_PATH].includes(path)) {
        return true
    }
    return false
}

export default routerConfig